package com.ieasy.module.site.web.action;

import java.util.List;

import javax.inject.Inject;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ieasy.basic.model.Msg;
import com.ieasy.basic.util.cons.Const;
import com.ieasy.module.common.web.action.BaseController;
import com.ieasy.module.site.service.IMagicPicService;
import com.ieasy.module.site.web.form.MagicPicForm;

@Controller
@RequestMapping("/admin/site/magic")
public class MagicPicAction extends BaseController {

	@Inject
	private IMagicPicService magicService ;
	
	@RequestMapping("/magic_main_UI.do")
	public String magic_main_UI() {
		return Const.SITE + "magic_main_UI" ;
	}
	
	@RequestMapping("/magic_form_UI.do")
	public String magic_form_UI(MagicPicForm form, Model model) throws Exception {
		if(null != form.getId() && !"".equals(form.getId())) {
			model.addAttribute("id", form.getId()) ;
		}
		return Const.SITE + "magic_form_UI" ;
	}
	
	@RequestMapping("/magic_add_sub_UI.do")
	public String magic_add_sub_UI(MagicPicForm form, Model model) throws Exception {
		if(null != form.getId() && !"".equals(form.getId())) {
			model.addAttribute("id", form.getId()) ;
		}
		return Const.SITE + "magic_add_sub_UI" ;
	}
	
	@RequestMapping("/magic_update_sub_UI.do")
	public String magic_update_sub_UI(MagicPicForm form, Model model) throws Exception {
		if(null != form.getId() && !"".equals(form.getId())) {
			model.addAttribute("id", form.getId()) ;
		}
		return Const.SITE + "magic_update_sub_UI" ;
	}
	
	@RequestMapping("/add.do")
	@ResponseBody
	public Msg add(MagicPicForm form) throws Exception {
		Msg msg = this.magicService.add(form) ;
		return msg ;
	}
	
	@RequestMapping("/delete.do")
	@ResponseBody
	public Msg delete(MagicPicForm form) throws Exception {
		Msg msg = this.magicService.delete(form) ;
		return msg ;
	}
	
	@RequestMapping("/update.do")
	@ResponseBody
	public Msg update(MagicPicForm form) throws Exception {
		Msg msg = this.magicService.update(form) ;
		return msg ;
	}
	
	@RequestMapping("/get.do")
	@ResponseBody
	public MagicPicForm get(MagicPicForm form) throws Exception {
		return this.magicService.get(form) ;
	}
	
	@RequestMapping("/tree.do")
	@ResponseBody
	public List<MagicPicForm> tree(MagicPicForm form) throws Exception {
		return this.magicService.tree(form.getPid()) ;
	}
	
	@RequestMapping("/dotNotNeedSession_listAll.do")
	@ResponseBody
	public List<MagicPicForm> listAll(MagicPicForm form) throws Exception {
		return this.magicService.listAll(form.getPid()) ;
	}
	
	@RequestMapping("/dotNotNeedSession_getByPid.do")
	@ResponseBody
	public List<MagicPicForm> dotNotNeedSession_getByPid(MagicPicForm form) throws Exception {
		return this.magicService.getByPid(form.getId()) ;
	}
	
	@RequestMapping("/doNotNeedAuth_closeVote.do")
	@ResponseBody
	public Msg doNotNeedAuth_closeVote(MagicPicForm form) {
		this.magicService.closeVote(form.getId());
		return new Msg(true, "操作成功") ;
	}
	
	@RequestMapping("/doNotNeedAuth_sort.do")
	@ResponseBody
	public void doNotNeedAuth_sort(int oldSort, int newSort, String id, String pid) {
		this.magicService.updateResetSort(oldSort, newSort, id, pid) ;
	}
	
	@RequestMapping("/magic_view_UI.do")
	public String magic_view_UI(MagicPicForm form) throws Exception {
		return Const.SITE + "magic_view_UI" ;
	}
}
